package org.everyday;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * @version v1.0.0
 * 创建时间：2022/7/20 09:13
 */
public class L1260 {
    public List<List<Integer>> shiftGrid(int[][] grid, int k) {
        int m = grid.length;
        int n = grid[0].length;
        List<List<Integer>> res = new ArrayList<>();
        for (int i = 0; i < m; i++) {
            List<Integer> row = new ArrayList<Integer>();
            for (int j = 0; j < n; j++) {
                row.add(0);
            }
            res.add(row);
        }
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                int totalIndex = (i * n + j + k) % (m * n);
                res.get(totalIndex / n).set(totalIndex % n, grid[i][j]);
            }
        }
        return res;
    }

    public static void main(String[] args) {
        new L1260().shiftGrid(new int[][]{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, 1);
    }

}
